from ..models import *
from .error_code import *
from .exception import *


def get_real_question(question_id):
    tmp_question = Question.query.filter_by(question_id=question_id).first()
    if tmp_question is None:
        raise APIException(NO_QUESTION_EXISTS)
    question_type = tmp_question.question_type
    real_question = None

    if question_type == 1:
        real_question = QuestionOfFillBlank.query.filter_by(question_id=question_id).limit(1).first()
    elif question_type == 2:
        real_question = QuestionOfSelect.query.filter_by(question_id=question_id).limit(1).first()
    elif question_type == 3:
        real_question = QuestionOfJudge.query.filter_by(question_id=question_id).limit(1).first()
    elif question_type == 4:
        real_question = QuestionOfProgramFillBlank.query.filter_by(question_id=question_id).limit(1).first()
    elif question_type == 5:
        real_question = QuestionOfProgramModify.query.filter_by(question_id=question_id).limit(1).first()
    elif question_type == 6:
        real_question = QuestionOfProgram.query.filter_by(question_id=question_id).limit(1).first()

    return real_question, question_type
